﻿@model IEnumerable<BootyBay.Models.StoreUser>

@if (ViewBag.ErrorMessage != null)
{
    <div>
        <p style="color:red">@ViewBag.ErrorMessage</p>
    </div>
}
@if (ViewBag.SuccessMessage != null)
{
    <div>
        <p style="color:green">@ViewBag.SuccessMessage</p>
    </div>
}
<div id="storeuserList">
    <table>
        <tr>
            <th>Users</th>
            <th>Action</th>
        </tr>
        @if (Model.Count() == 0)
        {
            <tr>
                <td colspan="2">
                    No data, please add new user.
                </td>
            </tr>
        }
        else
        {
            foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Ajax.ActionLink(@item.UserName, "ListApplication", new { username = item.UserName }, new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "applicationListContent", InsertionMode = InsertionMode.Replace })
                    </td>
                    <td>
                        @Ajax.ActionLink("Delete", "RemoveUser", new { id = item.Id }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "storeuserListContent", InsertionMode = InsertionMode.Replace })
                    </td>
                </tr>
            }
        }
        <tr>
            <td>
                @using (Ajax.BeginForm("AddUser", new { Id = 0 }, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "storeuserListContent", InsertionMode = InsertionMode.Replace }, new { id = "AddUserForm" }))
                {
                    <input type="text" name="UserName" />
                }
            </td>
            <td>
                <a href="javascript:{}" onclick="$('#AddUserForm').submit()">Add</a>
            </td>
        </tr>

    </table>
</div>
<div id="applicationList">
    <div id="applicationListContent">
    </div>
</div>